﻿var zombies = zombies || {};

zombies.editProfile = function () {
    var self = this;
    //edit information
    self.ChannelName = ko.observable();
    self.PubId = ko.observable();
    self.Address = ko.observable();
    self.Facebook = ko.observable();
    self.Phone = ko.observable();

    self.doEdit = function () {
        var dataToEdit = {
            CompanyName: self.ChannelName,
            PubId: self.PubId,
            Address: self.Address,
            Phone: self.Phone,
            Facebook: self.Facebook
        };
        $.ajax({
            type: "PUT",
            url: "/api/Publisher/PutChannel",
            data: ko.toJSON(dataToEdit), //Convert the Observable Data into JSON
            contentType: "application/json",
            dataType: 'json'
        }).done(function () {
            toastr.success('Chỉnh Sửa Thông Tinh QC Thành Công!');
        }).fail(function () {
            toastr.error('Sửa thất bại');
        });
    };
};


var loadChanel = function () {
    $.ajax({
        type: "GET",
        url: "/api/Publisher/GetCurrentChannel",
        contentType: "application/json",
        dataType: 'json'
    }).done(function (item) {
        editProfileModel.PubId(item.PubId);
        editProfileModel.ChannelName(item.ChannelName);
        editProfileModel.Address(item.Address);
        editProfileModel.Facebook(item.Facebook);
        editProfileModel.Phone(item.Phone);
    }).fail(function () {
    });
};

var editProfileModel;
$(document).ready(function () {
    editProfileModel = new zombies.editProfile();
    loadChanel();

    ko.applyBindings(editProfileModel, document.getElementById("content_publisher"));

//    $('#coverupload').uploadFile({
//        url: "/api/Publisher/PostCover",
//        method: "POST",
//        allowedTypes: "jpg,png,gif",
//        fileName: "myfile",
//        multiple: false,
//        onSuccess: function (files, data, xhr) {
//            editProfileModel.ChannelCover('../Advertise/' + files);
//        },
//        onError: function (files, status, errMsg) {
//            alert("Tải ảnh cover thất bại");
//        }
//    });
});